﻿using System;
using System.Collections.Generic;
using ZyGames.DZPocker.Model;
using ZyGames.Framework.Cache.Generic;
using ZyGames.Framework.Game.Cache;
using ZyGames.Framework.Game.Context;
using ZyGames.Framework.Game.Contract;
using ZyGames.Framework.Game.Contract.Action;
using ZyGames.Framework.Game.Lang;
using ZyGames.Framework.Game.Service;
using System.Linq;
using ZyGames.DZPocker.Bll.Logic;
using ZyGames.DZPocker.Script;
using System.Text.RegularExpressions;
using ZyGames.Framework.Net;
using ZyGames.Framework.Common.Serialization;
using ZyGames.DZPocker.Tools;

namespace ZyGames.DZPocker.Script.CsScript.Action
{
	/// <summary>
	/// 删除消息界面邀请信息
	/// </summary>
	public class Action30058 : BaseAction
	{
		private int tableId;
		private int inviteUserId;
		private int beInvitedUserId;
		private bool result = true;
		private string log = "";
		public Action30058(HttpGet actionGetter)
			: base((short)ActionType.DZDeleteInviteInfo, actionGetter)
		{
		}
		public override bool GetUrlElement()
		{
			if (httpGet.GetInt("TableId", ref tableId) &&
				httpGet.GetInt("InviteUserId", ref inviteUserId) &&
				httpGet.GetInt("BeInvitedUserId", ref beInvitedUserId))
			{
				return true;
			}
			return false;
		}

		public override bool TakeAction()
		{
			if (tableId != 0)
			{
				var _currentTable = GameRoom.Current.GetTableData(tableId);
				if (_currentTable == null)
				{
					Tool.WriteWarmingLine("消息30057获得房间不存在");
					log = "房间不存在";
					result = false;
					return true;
				}
			}

			var inviteUser = GameTable.Current.GetUser(inviteUserId);
			if (inviteUser == null)
			{
				Tool.WriteWarmingLine("消息30058邀请的玩家不存在");
				log = "删除失败";
				result = false;
				return true;
			}

			var beInviteUser = GameTable.Current.GetUser(beInvitedUserId);
			if (beInviteUser == null)
			{
				Tool.WriteWarmingLine("消息30058被邀请的玩家不存在");
				log = "删除失败";
				result = false;
				return true;
			}

			result = GameTable.Current.DeleteInvite(tableId, inviteUserId, beInvitedUserId);
			log = result ? "删除成功" : "删除失败";
			return true;
		}

		public override void BuildPacket()
		{
			this.PushIntoStack(this.result);
			this.PushIntoStack(this.log);
		}
	}
}
